<?php
/**
 * Joomla! 1.5 component PB-Roster
 *
 * @version $Id: pbroster.php 2010-09-10 10:03:33 svn $
 * @author ML@pixelbyte.dk
 * @package Joomla
 * @subpackage PB-Roster
 * @copyright (C) 2010- pixelbyte.dk
 * @license GNU/GPL
 *
 * A World of Warcraft Guild Roster
 *
 */

//&nbsp;

// No direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
JHTML::_('behavior.tooltip');

function getView() {
 /**
   *  getView() Used to get the view of the page.
   */
  $my_GET = parse_query($_SERVER['REQUEST_URI']);
  
  $enabled = 0;
  if (getPlugin('char_roster')) {
	$enabled = enabledPluginCRoster();
  }
  
  if(isset($_POST['force_roster_update'])) {
    //Lets double check if we have admin rights
	if (HTML_AdminRoster::getAdminRights())
	  updateDatabase("");
  }

  // Make sure we have a default view
  if( !JRequest::getVar( 'view' )) {
	JRequest::setVar('view', 'pbroster' );
  }
  
  if(isset($_POST['loginForm']))
    HTML_AdminRoster::showGuildAdmin("","");
 
  $view = JRequest::getVar('view');
  
  switch($view) {
	case 'character':
      if (getPlugin('char_roster')) {
        if (enabledPluginCRoster())
          viewCharacter("");
	    else {
	      displayErrorMessage("Character Roster is currently disabled.");
		  $currentUrl = JURI::current();
          echo "<meta http-equiv='refresh' content='4;URL=".$currentUrl."'>";
		}
	  }
	  else {
	    displayErrorMessage("The Character Roster does not appear to be installed. <br />Please visit pixelbyte.dk for more information.");
		$currentUrl = JURI::current();
        echo "<meta http-equiv='refresh' content='6;URL=".$currentUrl."'>";
	  }
      break;
	/*case 'character-gear':
      if (getPlugin('char_roster')) {
        if (enabledPluginCRoster())
          viewCharacterGear("");
	    else {
	      displayErrorMessage("Character Roster is currently disabled.");
		  $currentUrl = JURI::current();
          echo "<meta http-equiv='refresh' content='4;URL=".$currentUrl."'>";
		}
	  }
	  else {
	    displayErrorMessage("The Character Roster does not appear to be installed. <br />Please visit pixelbyte.dk for more information.");
		$currentUrl = JURI::current();
        echo "<meta http-equiv='refresh' content='6;URL=".$currentUrl."'>";
	  }
      break;*/
	case 'stats':	  viewStats();	   break;
	case 'admin':	  viewAdmin();	   break;
	case 'account':	  if ($enabled) {viewAccount();} else {viewRoster("");} break;
	case 'pbroster':  viewRoster("");  break;
    default:		  viewRoster("");  break;
  }
  
  echo '<br>Im a page<br>';
}

function displayErrorMessage($message) {  
    $document = & JFactory :: getDocument();
	$document->addStyleSheet(getRosterPath("roster").'css/guild_roster.css');
	$document->addScript(getRosterPath("roster").'js/jquery-1.4.2.min.js');
	$document->addScript(getRosterPath("roster").'js/tinybox_load.js');
	
	$config = getGuildConfig();
	
	if (hasPBTemplate()) {
	  $got_pbtheme = 'margin-left:-5px;';
	}
	else {
      $got_pbtheme = '';
	}
	
	echo '<div class="RosterPage" style="width:'.$config->roster_width.'px;'.$got_pbtheme.'">';
	echo '<div class="LoadPage" style="width:100%;height:100%">';
	echo '<img src="'.getRosterPath("images").'load-bg.jpg" width="100%" height="100%">';
	echo '<div id="popup1" class="popup_block"><div id="displayMessage">';
	echo '<span class="text">'.$message.'</span>';
	echo '<span class="quote">&nbsp;</span>';
	echo '<span class="redirect">'.JText::_( 'COM_PBROSTER_MESSAGE_NOTICE_REDIRECT' ).'</span>';
	//echo '<div id="updateMember">here</div>';
	echo '<div class="pre_loader"><img src="'.getRosterPath("images").'loaders/preload.gif"></div></div></div>';
	echo '</div></div>';
}

function displayNoticeMessage($message) {  
    $document = & JFactory :: getDocument();
	$document->addStyleSheet(getRosterPath("roster").'css/guild_roster.css');
	$document->addScript(getRosterPath("roster").'js/jquery-1.4.2.min.js');
	$document->addScript(getRosterPath("roster").'js/tinybox_load.js');
	
	$config = getGuildConfig();
	
	if (hasPBTemplate()) {
	  $got_pbtheme = 'margin-left:-5px;';
	}
	else {
      $got_pbtheme = '';
	}
	
	echo '<div class="RosterPage" style="width:'.$config->roster_width.'px;'.$got_pbtheme.'">';
	echo '<div class="LoadPage" style="width:100%;height:100%">';
	echo '<img src="'.getRosterPath("images").'load-bg.jpg" width="100%" height="100%">';
	echo '<div id="popup1" class="popup_block"><div id="displayMessage">';
	echo '<span class="text">'.$message.'</span>';
	echo '<span class="quote">&nbsp;</span>';
	echo '<span class="redirect">'.JText::_( 'COM_PBROSTER_MESSAGE_NOTICE_REDIRECT' ).'</span>';
	echo '<div class="pre_loader"><img src="'.getRosterPath("images").'loaders/preload.gif"></div></div></div>';
	echo '</div></div>';
}

function rosterHeader($config) {
  $ginfo = getGuildInfo();
  foreach ( $ginfo as $guild ) {  
  // Get faction
  if ($guild->faction == 0)
	$faction = "alliance";
  else
	$faction = "horde";
	
  // Check template setting
  $template = getRosterTemplateAdjust($config);
	
  // Get language domain for wowhead
  $domain = get_wowhead_domain($guild->lang);
  
  // Prepare perk tooltip
  $perk_tip = get_perk_tooltip($guild->level);

  // Build emblem background banner
  if ($config->roster_banner != "")
    $banner = getRosterPath("images").$config->roster_banner;
  else
    $banner = getRosterPath("images").'guild/roster/bg-'.$faction.'.jpg';
?>
  <div class="RosterPage" style="width:<?php echo $config->roster_width; ?>px;<?php echo $template->marginleft.$template->margintop; ?>">
	  <div class="roster-wrapper">
	    <div class="roster-inner-wrapper">
		  <div class="roster">
		    <div class="roster_banner">
			  <div class="roster_banner_img">
			    <img src="<?php echo $banner; ?>" width="100%" height="445px">
			  </div>
			  <div class="roster_banner_guild sidebar-bg-<?php echo $faction; ?>"></div>
			  <div class="guild-tabard">
			    <canvas id="guild-tabard" width="240" height="240" style="display: inline;">
			      <div class="guild-tabard-default"></div>
			    </canvas>
			    <script type="text/javascript">
			      var tabard = new GuildTabard('guild-tabard', {
					'ring': '<?php echo $faction; ?>',
					'bg': [ 0, <?php echo $guild->emblemBackground; ?> ],
					'border': [ <?php echo $guild->emblemBorderStyle; ?>, <?php echo $guild->emblemBorderColor; ?> ],
					'emblem': [ <?php echo $guild->emblemIconStyle; ?>, <?php echo $guild->emblemIconColor; ?> ]
				  }, '<?php echo getRosterPath("images"); ?>');
				</script>
			  </div>
			  <div class="profile-info profile-guild-info">
				<div class="name">
				  <a href="<?php echo JRoute::_('index.php?option=com_pbroster&view=pbroster'); ?>"><?php echo $guild->name; ?></a>
				</div>				
				<div class="under-name">Level <span class="level tip" onmouseover="Tooltip.show(this, '#perk_tooltip');"><strong><?php echo $guild->level; ?></strong></span> <span class="faction"><?php echo ucwords($faction); ?></span> <?php echo JText::_( 'COM_PBROSTER_GUILD_ROSTER_GUILD_ON' ); ?><span class="comma">,</span>
				  <span class="server_<?php echo $faction; ?> tip" onmouseover="Tooltip.show(this, '#realm_tooltip');"><?php echo $guild->realm; ?></span>
				  
				  <span id="perk_tooltip" style="display: none;"><ul><li><img class="icon-frame frame-56" src="<?php echo getRosterPath("images").'icons/perks/large/'.$guild->level.'.jpg'; ?>">
				  <h3><?php echo $perk_tip->name; ?></h3></li><li class="color-tooltip-yellow"><?php echo $perk_tip->desc; ?></li></ul></span>
				  
				  <span id="realm_tooltip" style="display: none;"><ul><li><h3><?php echo $guild->realm; ?></h3></li><li class="color-tooltip-yellow"><?php echo $guild->battleGroup; ?></li></ul></span>
				  .
				  <span class="members"><?php echo getNumMembers().' '.JText::_( 'COM_PBROSTER_GUILD_ROSTER_MEMBERS' ); ?></span>
				</div>
				<div class="achievements"><?php echo $guild->achievement; ?></div>
				<div class="errors"><span class="noscript"><noscript><span class="icon"></span>This page uses Javascript. Your browser either doesn't support Javascript or you have it turned off.</noscript></span></div>				
			  </div>
			</div>		  
<?php
  }

}

class HTML_Roster {

  function includeRosterDocs($config) {
    $document = & JFactory :: getDocument();
	$document->addStyleSheet(getRosterPath("roster").'css/main.css');
	$document->addStyleSheet(getRosterPath("roster").'css/guild_roster.css');
	$document->addStyleSheet(getRosterPath("roster").'css/news.css');
	$document->addStyleSheet(getRosterPath("roster").'css/screenshot.css');
	$document->addStyleSheet(getRosterPath("roster").'css/flags_16.css');
	$document->addStyleSheet(getRosterPath("roster").'css/flags_32.css');
	$document->addScript(getRosterPath("roster").'js/jquery-1.4.2.min.js');
	$document->addScript(getRosterPath("roster").'js/core.js');
	$document->addScript(getRosterPath("roster").'js/guild-tabard.js');
	$document->addScript(getRosterPath("roster").'js/tooltip.js');
	$document->addScript(getRosterPath("roster").'js/tinybox.js');
	$document->addScript('http://static.wowhead.com/widgets/power.js');
	$document->addStyleSheet(getRosterPath("roster").'css/tablesorter.css');	
  }
  
  function includeStatsDocs($config) {
    $document = & JFactory :: getDocument();
	$document->addStyleSheet(getRosterPath("roster").'css/main.css');
	$document->addStyleSheet(getRosterPath("roster").'css/guild_roster.css');
	$document->addStyleSheet(getRosterPath("roster").'css/news.css');
	$document->addScript(getRosterPath("roster").'js/jquery-1.4.2.min.js');
	$document->addScript(getRosterPath("roster").'js/core.js');
	$document->addScript(getRosterPath("roster").'js/guild-tabard.js');
	$document->addScript(getRosterPath("roster").'js/tooltip.js');
	$document->addScript('http://static.wowhead.com/widgets/power.js');

	// Modify breadcrumbs
	$mainframe = &JFactory::getApplication();
	$app =& JFactory::getApplication();
	$pathway =& $app->getPathway();
	//$pathway->addItem(JText::_( 'COM_PBROSTER_SUBTAB_BUTTON_GUILD_STATS' ), JRoute::_('index.php?option=com_pbroster&view=pbroster');
	$pathway->addItem(JText::_( 'COM_PBROSTER_MENU_ITEM_ROSTER_STATS' ));
  }
  
  function headerMenu($config, $active) {
    $enabled = 0;
	if (getPlugin('char_roster')) {
	  $enabled = enabledPluginCRoster();
	}
	
    echo '<ul class="profile-sidebar-menu" id="profile-sidebar-menu">';
    if ($config->menu_roster == 'yes') {
      echo '<li class="'.($active == 'roster' ? 'active' : '').'"><a title="'.JText::_( 'COM_PBROSTER_MENU_ITEM_ROSTER' ).'" href="'.JRoute::_('index.php?option=com_pbroster&view=pbroster').'"><span class="arrow"><span class="icon">'.JText::_( 'COM_PBROSTER_MENU_ITEM_ROSTER' ).'</span></span></a></li>'."\n";
    }
    if ($config->menu_stats == 'yes') {
      echo '<li class="'.($active == 'stats' ? 'active' : '').'"><a title="'.JText::_( 'COM_PBROSTER_MENU_ITEM_ROSTER_STATS' ).'" href="'.JRoute::_('index.php?option=com_pbroster&view=stats').'"><span class="arrow"><span class="icon">'.JText::_( 'COM_PBROSTER_MENU_ITEM_ROSTER_STATS' ).'</span></span></a></li>'."\n";
    }
    /*if ($config->menu_cal == 'yes') {
      echo '<li class="'.($active == 'calendar' ? 'active' : '').'"><a title="'.JText::_( 'COM_PBROSTER_CALENDAR_GUILD_CALENDAR' ).'" href="'.JRoute::_('index.php?option=com_pbroster&view=calendar').'"><span class="arrow"><span class="icon">'.JText::_( 'COM_PBROSTER_CALENDAR_GUILD_CALENDAR' ).'</span></span></a></li>'."\n";
    }
  
    if (getPlugin('member_notes')) {
      if (enabledPluginMemberNotes()) {
	    if ($config->menu_notes == 'yes') {
          echo '<li class="'.($active == 'notes' ? 'active' : '').'"><a title="'.JText::_( 'SUBTAB_BUTTON_MEMBER_NOTES' ).'" href="'.JRoute::_('index.php?option=com_pbroster&view=notes').'"><span class="arrow"><span class="icon">'.JText::_( 'SUBTAB_BUTTON_MEMBER_NOTES' ).'</span></span></a></li>'."\n";
	    }
	  }
    }*/
	if ($enabled && HTML_MemberRoster::getMemberRights()) {
      echo '<li class="'.($active == 'member' ? 'active' : '').'"><a class="has-submenu" title="'.JText::_( 'COM_PBROSTER_MENU_ITEM_ACCOUNT' ).'" href="'.JRoute::_('index.php?option=com_pbroster&view=account').'" class="vault" rel="np"><span class="arrow"><span class="icon">'.JText::_( 'COM_PBROSTER_MENU_ITEM_ACCOUNT' ).'</span></span></a></li>'."\n";
    }
    else if ($enabled){
      echo '<li class="disabled tooltip_general" onmouseover="Tooltip.show(this, \'#account_button\');"><a href="javascript:;" class="vault" rel="np"><span class="arrow"><span class="icon">'.JText::_( 'COM_PBROSTER_MENU_ITEM_ACCOUNT' ).'</span></span></a></li>';
	  echo '<span id="account_button" style="display: none;"><ul><li><h3>'.JText::_( 'COM_PBROSTER_MENU_ITEM_ACCOUNT' ).'</h3></li><li class="color-tooltip-yellow">'.JText::_( 'COM_PBROSTER_MENU_TOOLTIP_ACCOUNT' ).'</li></ul></span>';
    }
	else {
      if (HTML_AdminRoster::getAdminRights()) {
        echo '<li class="'.($active == 'admin' ? 'active' : '').'"><a title="'.JText::_( 'COM_PBROSTER_MENU_ITEM_ADMIN' ).'" href="'.JRoute::_('index.php?option=com_pbroster&view=admin&page=member').'" class="vault" rel="np"><span class="arrow"><span class="icon">'.JText::_( 'COM_PBROSTER_MENU_ITEM_ADMIN' ).'</span></span></a></li>'."\n";
      }
      else {
        echo '<li class="disabled tooltip_general" onmouseover="Tooltip.show(this, \'#admin_button\');"><a href="javascript:;" class="vault" rel="np"><span class="arrow"><span class="icon">'.JText::_( 'COM_PBROSTER_MENU_ITEM_ADMIN' ).'</span></span></a></li>';
	    echo '<span id="admin_button" style="display: none;"><ul><li><h3>'.JText::_( 'COM_PBROSTER_MENU_ITEM_ADMIN' ).'</h3></li><li class="color-tooltip-yellow">'.JText::_( 'COM_PBROSTER_MENU_TOOLTIP_ADMIN' ).'</li></ul></span>';
      }
    }
  }
  
  function footerButtons() {
    echo '</div></div></div>'; //rosterHeader()
  }
  
  function rosterFooter($config) {
    $db =& JFactory::getDBO();
    $query = "SELECT * FROM #__guildroster_main";
    $db->setQuery($query);

	$lostTime = 0;
    $cache = $db->loadObject();
    if( $db->getErrorNum() || !isset($cache) || !isset($cache->cache_date))
	  $lostTime = 1;
	 
	echo '<div class="guild_roster_footer">';
	echo '<img style="position:absolute;z-index:1" src="'.getRosterPath("images").'decor_top.jpg'.'" width="100%" height="40px">';
	echo '<div style="padding: 5px;">';
	if ($lostTime)
	  echo '<span class="roster_updated"><a href="http://pixelbyte.dk">PB-Roster</a> '.JText::_( 'COM_PBROSTER_GUILD_ROSTER_LAST_ARMORY_UPDATE_LOST' ).'</span>';
	else {
      $diff = time() - strtotime($cache->cache_date);
      $diffDays = $diff / 60 / 60 / 24;
	  echo '<span class="roster_updated"><a href="http://pixelbyte.dk">PB-Roster</a> '.JText::_( 'COM_PBROSTER_GUILD_ROSTER_LAST_ARMORY_UPDATE' ).' : ';
      echo dateDiff(time(), strtotime($cache->cache_date), 6);
      echo ' '.JText::_( 'COM_PBROSTER_GUILD_ROSTER_LAST_ARMORY_UPDATE_AGO' ).'.</span>';
	}
	echo '</div></div></div></div>';
  }
  
  function rosterNews($config, $amount) {
    $ginfo = getGuildInfo();
	$newsId = 0;
	
    foreach ( $ginfo as $guild ) {
	  //$newsId = $guild->newsid;
	  $note = $guild->guild_info;
	}
	
	echo '<div class="summary-activity"><h3 class="category ">'.JText::_( 'COM_PBROSTER_GUILD_NEWS_CATEGORY' ).'</h3>'."\n";
	echo $note;
	
	
	/*if (test_table_name())
	  echo '<br />found';
	else
	  echo '<br />not found';*/
	
	echo '</div>';
	
  }

  function showRoster($rows, $option) {	
	$config = getGuildConfig();
	HTML_Roster::includeRosterDocs($config);
	$account =& JFactory::getUser();

    rosterHeader($config);
	echo '<div class="RosterMenu alliance-menu">';
	HTML_Roster::headerMenu($config, "roster");
	echo '</ul>'; // RosterMenu
	HTML_Roster::rosterNews($config, 4);
	echo '</div>'; // RosterMenu
	
	$got_profile_config_options = false;
	$faction = "horde";
	
	$ginfo = getGuildInfo();	
    foreach ( $ginfo as $guild ) {
	  if ($guild->faction == 0)
		$faction= "alliance";
	  else
		$faction = "horde";
	}
	
	$enabled = 0;
	if (getPlugin('char_roster')) {
	  $enabled = enabledPluginCRoster();
	  $profile_options = getAccountOptions($account->id);
	  if (isset($profile_options->id))
		$got_profile_config_options = true;
	}
	
	echo '<div class="tablewrapper">';
	echo '<div class="search_header">';
	echo '<img style="position:absolute;" src="'.getRosterPath("images").'decor_top.jpg'.'" width="100%" height="40px">';
?>
		  <div id="tableheader">
        	<div class="rost_search">
                <img height=24 align="left" src="<?php echo getRosterPath("images"); ?>sorter/zoom.png">
                <input type="text" id="query" onkeyup="sorter.search('query')" />
				<span style="visibility:hidden;"><select id="columns" onchange="sorter.search('query')"></select></span>
            </div>
            <span class="details">
			    <div><a href="javascript:sorter.reset()"><?php echo JText::_( 'COM_PBROSTER_GUILD_ROSTER_RESET' ); ?></a></div>
				<div><?php echo JText::_( 'COM_PBROSTER_GUILD_ROSTER_RECORDS' ); ?> <span id="startrecord"></span>-<span id="endrecord"></span> <?php echo JText::_( 'COM_PBROSTER_GUILD_ROSTER_RECORDS_OF' ); ?> <span id="totalrecords"></span></div>
        	</span>
          </div>
		</div>
		<div id="roster">
        <table cellpadding="0" cellspacing="0" border="0" id="table" class="armoryRoster">
            <thead>
                <tr class="masthead">		
<?php
					if ($enabled) {
                      echo '<th width="16px" class="nosort"><h3></h3></th>';
					  
					  // Overide system config with user options
					  if ($got_profile_config_options) {
					    if ($profile_options->table_role_check == 1)			$config->table_role_check = "NO";
					    else if ($profile_options->table_role_check == 0)		$config->table_role_check = "YES";
						
					    if ($profile_options->table_prof1_check == 1)			$config->table_prof1_check = "NO";
					    else if ($profile_options->table_prof1_check == 0)		$config->table_prof1_check = "YES";
						
					    if ($profile_options->table_prof2_check == 1)			$config->table_prof2_check = "NO";
					    else if ($profile_options->table_prof2_check == 0)		$config->table_prof2_check = "YES";

					    if ($profile_options->table_ilevel_check == 1)			$config->table_ilevel_check = "NO";
					    else if ($profile_options->table_ilevel_check == 0)		$config->table_ilevel_check = "YES";
						
						if ($profile_options->table_default != -1)				$config->table_default = $profile_options->table_default;
						
						if ($profile_options->table_sort == 1 || $profile_options->table_sort == -1)
						  $config->table_sort = $profile_options->table_sort;
						  
						if ($profile_options->table_entries != 0)				$config->table_entries = $profile_options->table_entries;
					  }
					  
					  // Make adjustments if some of the optional tables are disabled and if thats the default sorting
					  if ($config->table_default == 5 && $config->table_role_check == "NO")		$config->table_default = 1;
					  if ($config->table_default == 6 && $config->table_prof1_check == "NO")	$config->table_default = 1;
					  if ($config->table_default == 7 && $config->table_prof2_check == "NO")	$config->table_default = 1;
					  if ($config->table_default == 8 && $config->table_ilevel_check == "NO")	$config->table_default = 1;
					
					  // We also have to adjust if default sorting is higher than 4 and some of the tables ar disabled, kinda messy
					  if ($config->table_default > 4 && $config->table_role_check == "NO")		$config->table_default--;
					  if ($config->table_default > 4 && $config->table_prof1_check == "NO")		$config->table_default--;
					  if ($config->table_default > 4 && $config->table_prof2_check == "NO")		$config->table_default--;
					  if ($config->table_default > 4 && $config->table_ilevel_check == "NO")	$config->table_default--;
						
					  // And finally bump for the first no-sort table
					  $config->table_default += 1;
					  
					}
					else { // fix if char_roster is disabled and default sorting is higher than 5, else the sorting breaks as non char roster only have 5 tables.
					  if ($config->table_default > 5)
					  $config->table_default = 5;
					}
					echo '<th width="'.$config->table_level.'px"><h3>'.JText::_( 'COM_PBROSTER_GUILD_ROSTER_LEVEL' ).'</h3></th>';
                    echo '<th><h3>'.JText::_( 'COM_PBROSTER_GUILD_ROSTER_CHAR_NAME' ).'</h3></th>';
					echo '<th width="'.$config->table_ach.'px"><h3>'.JText::_( 'COM_PBROSTER_GUILD_ROSTER_ACH_POINTS' ).'</h3></th>';
					echo '<th width="'.$config->table_race.'px"><h3>'.JText::_( 'COM_PBROSTER_GUILD_ROSTER_RACE' ).'</h3></th>';
                    echo '<th width="'.$config->table_class.'px"><h3>'.JText::_( 'COM_PBROSTER_GUILD_ROSTER_CLASS' ).'</h3></th>'."\n";
					if ($enabled && $config->table_role_check == "YES") {
					  echo '<th width="'.$config->table_role.'px"><h3>'.JText::_( 'COM_PBROSTER_GUILD_ROSTER_ROLE' ).'</h3></th>';
					}
					if ($enabled && $config->table_prof1_check == "YES") {
					  echo '<th width="'.$config->table_prof1.'px"><h3>1</h3></th>';
					}
					if ($enabled && $config->table_prof2_check == "YES") {
					  echo '<th width="'.$config->table_prof2.'px"><h3>2</h3></th>';
					}
					if ($enabled && $config->table_ilevel_check == "YES") {
					  echo '<th width="'.$config->table_ilevel.'px"><h3>'.JText::_( 'COM_PBROSTER_GUILD_ROSTER_ILEVEL' ).'</h3></th>';
					}
                    echo '<th width="'.$config->table_rank.'px"><h3>'.JText::_( 'COM_PBROSTER_GUILD_ROSTER_RANK' ).'</h3></th>';
					if ($enabled && HTML_MemberRoster::getMemberRights()) { // Only show if logged in
					  echo '<th width="40px"><h3>&nbsp;<img style="margin: 0 0 -3px;" title="Profile" width="14" height="14" src="'.getRosterPath("images").'icons/'.$faction.'.jpg" alt=""/></h3></th>';
					}
					
			echo '</tr></thead><tbody>';						
                
			foreach ( $rows as $row ) {
              echo '<tr>';
			  
			  // Get profile and account information
			  $got_profile = false;
			  if ($enabled) {
			    if ($row->jaccount != "") {
				  $profile_account = getAccountProfile($row->jaccount);
				  $got_profile = true;
				}
			  }
			  
			  // Last Update
			  if ($enabled) {
			    echo '<td><img class="tip" style="border-bottom: 0 none;" onmouseover="Tooltip.show(this, \'#lupdate-'.$row->name.'\');" src="'.return_cache_color($row->last_updated).'"></td>';
			  }
			  		  
			  // Level & Screenshot
			  echo '<td><span style="display:none;">*'.$row->level.'-</span><span style="float: right;">'.$row->level.'</span>';
			  if ($enabled) {
				if ($row->screenshot != "") {
				  echo '<a class="poplight" rel="screenshot-'.$row->name.'" href="#?w=800"><span class="scroll"><img width="800" src="'.getRosterPath("images").'icons/scroll.png"></span></a>'."\n";
				  echo '<div id="screenshot-'.$row->name.'" class="popup_block" ><span class="screenshot"><img src="'.$row->screenshot.'" alt=""/></span></div>';
				}
				// Put hidden search options here
				if (HTML_MemberRoster::getMemberRights()) {
				  echo '<span style="display:none;">';
				  if ($got_profile && $row->ac_type == 0) // alt
				    echo '*alt '.getAccountMainCharacter($row->jaccount);
				  else if ($got_profile && $row->ac_type == 1) // main
				    echo '*main';
				  echo '</span>';
				}
			  }
			  echo '</td>';
			  
			  // Character Name
			  if ($enabled) {
				echo '<td><div class="ros_name'.$row->classId.'"><a onmouseover="Tooltip.show(this, \'#char-name-'.$row->name.'\', { location: \'topCenter\' });" href="'.JRoute::_('index.php?option=com_pbroster&view=character&ch='.$row->name).'">'.$row->name.'</a></div></td>'."\n";
			  }
			  else // Character Name with armory link
			    echo '<td><div class="ros_name'.$row->classId.'">'.$row->charUrl.''.$row->name.'</a></div></td>';
				
			  // Achivement Points
			  echo '<td align="right">'.$row->points.'<span class="achPts"></span></td>';

			  // Race
			  echo '<td><span style="display: none;">'.return_race_lang($row->raceId).'</span><span style="display: none;">'.$row->genderId.'</span>'."\n";
			  echo '<img class="tip" onmouseover="Tooltip.show(this, \''.return_race_lang($row->raceId).'\');" style="border: 1px solid #1c1c1c;" src="'.getRosterPath("images").'icons/races/small/'.$row->raceId.'-'.$row->genderId.'.jpg" height=20 align="right"></td>'."\n";
			  
			  // Class
			  echo '<td><span style="display: none;">'.return_class_lang($row->classId).'</span>';
			  echo '<img class="tip" onmouseover="Tooltip.show(this, \''.return_class_lang($row->classId).'\');" style="border: 1px solid #1c1c1c;" height=20 align="left" src="'.getRosterPath("images").'icons/classes/small/'.$row->classId.'.jpg"></td>'."\n";

			  
			  // Class role
			  if ($enabled && $config->table_role_check == "YES") {

				echo '<td><span class="roles"><span style="display: none;">';
				
				$talent1 = @unserialize($row->talent_spec1);
				$talent2 = @unserialize($row->talent_spec2);

				$prime_talent = "";
				$prime_talent['prim'] = "none";
				
				if (!isset($talent1['prim'])) {
				  $talent1['prim'] = "";
				  $talent1['active'] = 0;
				}
				if (!isset($talent2['prim'])) {
				  $talent2['prim'] = "";
				  $talent2['active'] = 0;
				}
							  
			    if ($talent1['prim'] != "" && $talent1['active'] == 1) {
				  echo $talent1['prim'].'</span>';
				  // druid feral tank/dps hack
				  if ($row->classId == 11 && $talent1['treeTwo'] >= 30)
					echo '<span class="tip" onmouseover="Tooltip.show(this, \''.$talent1['prim'].'\');"><span class="icon-dps"></span><span class="icon-tank" title="'.$talent1['prim'].'"></span></span>';
				  else
				    echo '<span class="tip icon-'.return_role($talent1['icon']).'" onmouseover="Tooltip.show(this, \''.$talent1['prim'].'\');"></span>'."\n";
			    }
				else if ($talent2['prim'] != "" && $talent2['active'] == 1) {
				  echo $talent2['prim'].'</span>';
				  // druid feral tank/dps hack
				  if ($row->classId == 11 && $talent2['treeTwo'] >= 30)
					echo '<span class="tip" onmouseover="Tooltip.show(this, \''.$talent2['prim'].'\');"><span class="icon-dps"></span><span class="icon-tank" title="'.$talent2['prim'].'"></span></span>';
				  else
				    echo '<span class="tip icon-'.return_role($talent2['icon']).'" onmouseover="Tooltip.show(this, \''.$talent2['prim'].'\');"></span>'."\n";
				}
				else
			      echo 'none</span></td>';
				echo '</span></td>'."\n";
			  }

			  // Professions
			  if ($enabled) {
			    $display = "NO";
				$i=1;
				while($i <= 2) {
								
				  if ($i == 1) {
				    $prof = @unserialize($row->prof1);
					$side = "right";
					$display = $config->table_prof1_check;
				  }
				  else {
				    $prof = @unserialize($row->prof2);
					$side = "right";
					$display = $config->table_prof2_check;
				  }
					
				  if ($display == "YES" && is_array($prof)) {
				    echo '<td><span style="display: none;">'.$prof['name'].'</span>';
					echo '<img class="tip" onmouseover="Tooltip.show(this, \''.$prof['name'].' '.$prof['value'].'\');" style="border: 1px solid #1c1c1c;" src="'.getRosterPath("images").'icons/professions/small/'.$prof['id'].'.jpg" height=20 align="'.$side.'"></td>'."\n";
			      }
				  else if ($display == "NO") {
				    // do nothing
				  }
				  else
				    echo '<td><span style="display: none;"></span>';
			      $i++;
			    }
			  }
			  
			  // Item Level
			  if ($enabled && $config->table_ilevel_check == "YES") {
				$item = "";
				$i = 0;
				$ilev = 0;
				$ilev_num = 0;
				
				while ($i <= 19) {
				  switch ($i) {
					case  0: $item = unserialize($row->item_0);  $sp=0; break; //projectile?
					case  1: $item = unserialize($row->item_1);  $sp=1; break; //head
					case  2: $item = unserialize($row->item_2);  $sp=0; break; //neck
					case  3: $item = unserialize($row->item_3);  $sp=1; break; //shoulder
					case  4: $item = unserialize($row->item_4);  $sp=0; break; //shirt
					case  5: $item = unserialize($row->item_5);  $sp=1; break; //chest
					case  6: $item = unserialize($row->item_6);  $sp=0; break; //waist
					case  7: $item = unserialize($row->item_7);  $sp=1; break; //legs
					case  8: $item = unserialize($row->item_8);  $sp=0; break; //feet
					case  9: $item = unserialize($row->item_9);  $sp=1; break; //wrist
					case 10: $item = unserialize($row->item_10); $sp=1; break; //hands
					case 11: $item = unserialize($row->item_11); $sp=0; break; //ring1
					case 12: $item = unserialize($row->item_12); $sp=0; break; //ring2
					case 13: $item = unserialize($row->item_13); $sp=0; break; //trinket1
					case 14: $item = unserialize($row->item_14); $sp=0; break; //trinket2
					case 15: $item = unserialize($row->item_15); $sp=0; break; //cloak
					case 16: $item = unserialize($row->item_16); $sp=0; break; //mainhand
					case 17: $item = unserialize($row->item_17); $sp=0; break; //offhand
					case 18: $item = unserialize($row->item_18); $sp=0; break; //ranged
					case 19: $item = unserialize($row->item_19); $sp=0; break; //tabard
				  }
				  
				  $i++;

				  if ($item['level'] == "")
				    continue;
				
				  if ($item['level'] > 99) {
				    $ilev += (int)$item['level'];
					$ilev_num++;
				  }
				}
				  
				if ($ilev_num >= 1)
				  echo '<td align="right"><span style="color:'.return_ilevel_color(floor($ilev/$ilev_num)).'">'.floor($ilev/$ilev_num).'</span></td>';
				else
				  echo '<td align="right">0</td>';
			  } // end iLevel

			  echo '<td><span style="display: none;">'.$row->rank.'</span><div class="mLine'.$row->rank.'">';
			  if ($row->rank == 0)
			    echo '<img hspace="5" align="absmiddle" src="'.getRosterPath("images").'icons/icon-guildmaster.gif">';
			  echo return_rank($row->rank).'</div></td>';
			  // Profile
			  if ($enabled && HTML_MemberRoster::getMemberRights()) { // Only show if logged in
				if ($got_profile && isset($profile_account->country)) {
				  $country = getCountryCode($profile_account->country);
				  if ($country != "") // Some profiles does not have the country set
			        echo '<td><span style="display: none;">'.$profile_account->country.'</span><ul onmouseover="Tooltip.show(this, \'#pro_data-'.$row->name.'\');" class="f16"><li class="flag '.$country.' tip"></li></ul></td>';
				  else
				    echo '<td></td>';
				}
				else
				  echo '<td></td>';
			  }
              echo "</tr>\n"; // Thanks to zanson for solution.
		    }
?>
            </tbody>
        </table>
		</div>
        <div id="tablefooter">
          <div id="tablenav">
            	<div>
                    <img title="<?php echo JText::_( 'COM_PBROSTER_GUILD_ROSTER_NAV_FIRST' ); ?>" src="<?php echo getRosterPath("images"); ?>sorter/first.png" width="16" height="16" alt="<?php echo JText::_( 'COM_PBROSTER_GUILD_ROSTER_NAV_FIRST_PAGE' ); ?>" onclick="sorter.move(-1,true)" />
                    <img title="<?php echo JText::_( 'COM_PBROSTER_GUILD_ROSTER_NAV_PREVIOUS' ); ?>" src="<?php echo getRosterPath("images"); ?>sorter/previous.png" width="16" height="16" alt="<?php echo JText::_( 'COM_PBROSTER_GUILD_ROSTER_NAV_PREVIOUS_PAGE' ); ?>" onclick="sorter.move(-1)" />
                    <img title="<?php echo JText::_( 'COM_PBROSTER_GUILD_ROSTER_NAV_NEXT' ); ?>" src="<?php echo getRosterPath("images"); ?>sorter/next.png" width="16" height="16" alt="<?php echo JText::_( 'COM_PBROSTER_GUILD_ROSTER_NAV_NEXT_PAGE' ); ?>" onclick="sorter.move(1)" />
                    <img title="<?php echo JText::_( 'COM_PBROSTER_GUILD_ROSTER_NAV_LAST' ); ?>" src="<?php echo getRosterPath("images"); ?>sorter/last.png" width="16" height="16" alt="<?php echo JText::_( 'COM_PBROSTER_GUILD_ROSTER_NAV_LAST_PAGE' ); ?>" onclick="sorter.move(1,true)" />
                </div>
                <div>
                	<select id="pagedropdown"></select>
				</div>
                <div style="margin-top:3px">
                	<a href="javascript:sorter.showall()"><?php echo JText::_( 'COM_PBROSTER_GUILD_ROSTER_NAV_VIEW_ALL' ); ?></a>
                </div>
            </div>
			<div id="tablelocation">
            	<div>
                    <select onchange="sorter.size(this.value)">
                      <option value="5" <?php echo $config->table_entries == 5?"selected=\"selected\"":""?>>5</option>
                      <option value="10" <?php echo $config->table_entries == 10?"selected=\"selected\"":""?>>10</option>
                      <option value="20" <?php echo $config->table_entries == 20?"selected=\"selected\"":""?>>20</option>
                      <option value="50" <?php echo $config->table_entries == 50?"selected=\"selected\"":""?>>50</option>
                      <option value="100" <?php echo $config->table_entries == 100?"selected=\"selected\"":""?>>100</option>
                    </select>
                    <span><?php echo JText::_( 'COM_PBROSTER_GUILD_ROSTER_NAV_ENTRIES' ); ?></span>
                </div>
                <div class="page"><?php echo JText::_( 'COM_PBROSTER_GUILD_ROSTER_NAV_PAGE' ); ?> <span id="currentpage"></span> <?php echo JText::_( 'COM_PBROSTER_GUILD_ROSTER_NAV_PAGE_OF' ); ?> <span id="totalpages"></span></div>
            </div>
        </div>
	<script type="text/javascript" src="<?php echo getRosterPath("roster"); ?>js/sorter.js"></script>
	<script type="text/javascript">
	var sorter = new TINY.table.sorter('sorter','table',{
		headclass:'head',
		ascclass:'asc',
		descclass:'desc',
		evenclass:'evenrow',
		oddclass:'oddrow',
		evenselclass:'evenselected',
		oddselclass:'oddselected',
		paginate:true,
		size:<?php echo $config->table_entries; ?>,
		colddid:'columns',
		currentid:'currentpage',
		totalid:'totalpages',
		startingrecid:'startrecord',
		endingrecid:'endrecord',
		totalrecid:'totalrecords',
		hoverid:'selectedrow',
		pageddid:'pagedropdown',
		navid:'tablenav',
		sortcolumn:<?php echo $config->table_default; ?>,
		sortdir:<?php echo $config->table_sort; ?>,
		sum:[],
		init:true
	});
  </script>

<?php
	// Tooltip data
	if ($enabled) {
	  foreach ( $rows as $row ) {
	  
		// Last updated
		$diff = time() - strtotime($row->last_updated);
		$diffDays = $diff / 60 / 60 / 24;
		echo '<div id="lupdate-'.$row->name.'" style="display: none;"><div class="roster-icon-tooltip">'.$row->last_updated.'<div class="roster_updated_ago">'.dateDiff(time(), strtotime($row->last_updated), 6).' '.JText::_( 'COM_PBROSTER_GUILD_ROSTER_LAST_ARMORY_UPDATE_AGO' ).'</div></div></div>'."\n";
	  
	    // Profile
		if ($enabled && HTML_MemberRoster::getMemberRights()) { // Only show if logged in
		  if ($row->jaccount != "") {
		    $tt_gender_txt = '';
			$tt_country = '';
			$tt_country_code = '';
			$profile_account = getAccountProfile($row->jaccount);
			$tt_main_char = getAccountMainCharacter($row->jaccount);
			$gender = getAccountGender($profile_account->gender);
			
			// age
			if ($profile_account->dateOfBirth != 0 && $profile_account->monthOfBirth != 0 && $profile_account->yearOfBirth != 0)
			  $tt_age = calculateAge($profile_account->dateOfBirth.'-'.$profile_account->monthOfBirth.'-'.$profile_account->yearOfBirth);
			// gender
			if ($gender != "")
			  $tt_gender_txt = '<span class="tt_gender">'.$gender.' '.$tt_age.'</span>';
			// main
			if ($tt_main_char != "")
			  $tt_main_char = '<span class="tt_main">Main: <b>'.$tt_main_char.'</b></span>';
			else
			  $tt_main_char = '<span class="tt_main">&nbsp; <b>&nbsp;</b></span>';
			// country
			if (isset($profile_account->country)) {
			  $tt_country = '<span class="tt_location">'.$profile_account->country.'</span>';
			  $tt_country_code = getCountryCode($profile_account->country);
			  if ($tt_country_code != "")
			    $tt_country_code = '<ul class="f32"><li class="flag '.$tt_country_code.'">&nbsp;</li></ul>';
			}
			  
			echo '<div id="pro_data-'.$row->name.'" style="display: none;height:100px;"><div class="roster-icon-tooltip">'.$tt_main_char.''.$tt_gender_txt.''.$tt_country.''.$tt_country_code.'</div></div>'."\n";
		  }
		}
	  
		// Name tooltip
	    $talent1 = @unserialize($row->talent_spec1);
		$talent2 = @unserialize($row->talent_spec2);

		$prime_talent = "";
		$prime_talent['prim'] = "none";
				
		if (!isset($talent1['prim'])) {
		  $talent1['prim'] = "";
		  $talent1['active'] = 0;
		}
		if (!isset($talent2['prim'])) {
		  $talent2['prim'] = "";
		  $talent2['active'] = 0;
		}
				  
		if ($talent1['prim'] != "" && $talent1['active'] == 1)
		  $prime_talent = $talent1;
		else if ($talent2['prim'] != "" && $talent2['active'] == 1)
		  $prime_talent = $talent2;
				
		echo '<span id="char-name-'.$row->name.'" style="display: none;"><span class="character-tooltip">';			
		echo '<span class="icon-frame frame-56"><img width="56" height="56" src="'.return_avatar_src($row->avatar, $row->raceId, $row->genderId).'" alt=""/><span class="frame"></span></span>';
		echo '<h3>'.$row->name.'</h3>';
		if ($row->pvpicon != "")
		  echo '<span class="pvp_rank"><img src="'.getRosterPath("images").'icons/pvp/small/'.$row->pvpicon.'.jpg"></span>'."\n";
		echo '<div class="color-c'.$row->classId.'">'.$row->level.' '.return_race_lang($row->raceId).' '.($prime_talent['prim'] != "none" ? $prime_talent['prim'] : "").' '.return_class_lang($row->classId).'</div>';
		echo '<span class="character-achievementpoints">'.$row->points.'</span><span class="clear"><!-- --></span>'."\n";

		if ($prime_talent['prim'] != "none") {
		  echo '<span class="character-talents">';
		  echo '<span class="icon"><span class="icon-frame frame-12"><img width="12" height="12" src="'.getRosterPath("images").'icons/talents/18/'.$prime_talent['icon'].'.jpg" alt=""/></span></span>';
		  echo '<span class="points">'.$prime_talent['treeOne'].'<ins>/</ins>'.$prime_talent['treeTwo'].'<ins>/</ins>'.$prime_talent['treeThree'].'</span><span class="clear"><!-- --></span></span>';
		}
		echo '</span></span>'."\n";
	
	  }
	}

    HTML_Roster::footerButtons();
	HTML_Roster::rosterFooter($config);
  }
  
  function showStats($rows, $option) {
    $config = getGuildConfig();
    HTML_Roster::includeStatsDocs($config);

    $statistikGender = array('gender' => array(0, 0));
    $statistikRace   = array('race' => array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), 'male' => array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), 'female' => array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0));
    $statistikClass  = array('class' => array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
    $statistikRank   = array('rank' => array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
    $statistikLevel  = array('level' => array (0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0));
    $i=1;

    rosterHeader($config);
	echo '<div class="RosterMenu alliance-menu">';
	HTML_Roster::headerMenu($config, "stats");
	echo '</ul>'; // RosterMenu
	HTML_Roster::rosterNews($config, 4);
	echo '</div>'; // RosterMenu
	
    echo '<div class="stats-wrapper">';
	echo '<img style="position:relative;" src="'.getRosterPath("images").'decor_top.jpg'.'" width="100%" height="40px">';
	
	// Get faction id
	$guild = getGuildInfo();
	$faction = 0;
	foreach ( $guild as $ginfo ) {
	  $faction = $ginfo->faction;
	}
	
    foreach ( $rows as $row ) {
      $statistikGender['gender'][$row->genderId]++;
      $statistikRace['race'][$row->raceId]++;
      if ($row->genderId ==0)
        $statistikRace['male'][$row->raceId]++;
      else
        $statistikRace['female'][$row->raceId]++;
      $statistikClass['class'][$row->classId]++;
      $statistikRank['rank'][$row->rank]++;
      $statistikLevel['level'][$row->level]++;
      $i++;
    }
    $totalMembers = $i-1;
	
    // Race Breakdown
	if ($faction == 0)
      $rcId = array(11,3,7,1,4,22); // Alliance
	else
	  $rcId = array(10,2,6,8,5,9); // Horde
    echo '<div class="racial-stats">';
    echo '<h2>'.JText::_( 'COM_PBROSTER_STAT_ROSTER_RACE_BREAKDOWN' ).'</h2>';
    echo '<div class="race-container">';
    echo '<table><thead><tr>';

    $id=0;
    foreach ($rcId as $v) {
      $numA = number_format(($statistikRace['race'][$v] / $totalMembers)*100);
      echo '<td><h3><span id="racePercentage'.$id.'">'.$numA.'</span>%</h3></td>';
      $id++;
    }
    echo '<td class="genders" rowspan="5"><div class="g-pos">';
    echo '<div class="gender-box"><div class="male">';
    echo '<em><span id="genderNumber0">'.$statistikGender['gender'][0].'</span></em>';
    echo '<em><span id="genderPercentage0">'.number_format((($statistikGender['gender'][0])/$totalMembers)*100).'</span>%</em></div>';
    echo '<div class="female"><em><span id="genderPercentage1">'.number_format((($statistikGender['gender'][1])/$totalMembers)*100).'</span>%</em><em><span id="genderNumber1">'.$statistikGender['gender'][1].'</span></em></div></div></div></td></tr></thead>';
    echo '<tbody><tr class="graph-layout">';

    $id=0;
    foreach ($rcId as $v) {
      $numA = number_format((($statistikRace['race'][$v] / $totalMembers)*100)*1.3);
      echo '<td><div class="race-graph"><div style="height: '.$numA.'px;" id="raceBar'.$id.'" class="racebar"></div></div></td>';
      $id++;
    }
    echo '</tr></tbody><tbody><tr>';

    $id=0;
    foreach ($rcId as $v) {
      echo '<td><div id="raceShield'.$id.'" class="raceicon shield-'.$v.'"></div></td>';
      $id++;
    }
    echo '</tr><tr>';

    $id=0;
    foreach ($rcId as $v) {
      $numA = return_race_lang($v);
      echo '<td class="nameplate" align="center"><span id="raceName0">'.$numA.'</span></td>';
      $id++;
    }
    echo '</tr><tr>';

    $id=0;
    foreach ($rcId as $v) {
      $numA = JText::_($statistikRace['male'][$v]);
      $numB = JText::_($statistikRace['female'][$v]);
      $numD = $statistikRace['race'][$v];
      echo '<td><div class="race-icons">';
      echo '<img class="tip" id="raceIconMale0" onmouseover="Tooltip.show(this, \''.$numA.'\', { location: \'topRight\' });" src="'.getRosterPath("images").'icons/races/small/'.$v.'-0.jpg">';
      echo '<img class="tip" id="raceIconFemale0" onmouseover="Tooltip.show(this, \''.$numB.'\', { location: \'topRight\' });" src="'.getRosterPath("images").'icons/races/small/'.$v.'-1.jpg">';
      echo '</div><h4 id="raceNumber'.$id.'">'.$numD.'</h4></td>';
      $id++;
    }
    echo '</tr></tbody></table></div></div>';
 
    // Class Breakdown
    $clsId = array(6,11,3,8,2,5,4,7,9,1);

    echo '<div class="class-stats">';
    echo '<h2>'.JText::_( 'COM_PBROSTER_STAT_ROSTER_CLASS_BREAKDOWN' ).'</h2>';
    echo '<div class="class-container">';
    echo '<table><thead><tr>';

    $id=0;
    foreach ($clsId as $v) {
      $numA = number_format(($statistikClass['class'][$v] / $totalMembers) *100);
      echo '<td><h3><span id="classPercentage'.$id.'">'.$numA.'</span>%</h3></td>';
      $id++;
    }
    echo '</tr></thead><tbody><tr class="graph-layout">';

    $id=0;
    foreach ($clsId as $v) {
	  $numA = number_format((($statistikClass['class'][$v] / $totalMembers)*100)*3.3);
      echo '<td><div class="class-graph"><div style="height: '.$numA.'px;" class="classbar bar-'.$v.'" id="classBarStyle'.$id.'"></div></div></td>';
      $id++;
    }
    echo '</tr></tbody><tbody><tr>';

    $id=0;
    foreach ($clsId as $v) {
      $numA = JText::_(return_class_lang($v));
      echo '<td class="tip" id="raceIconMale0" onmouseover="Tooltip.show(this, \''.$numA.'\', { location: \'topRight\' });"><div class="classicon icon-'.$v.'" id="classIcon'.$id.'"></div></td>';
      $id++;
    }
    echo '</tr><tr>';

    $id=0;
    foreach ($clsId as $v) {
      $numA = $statistikClass['class'][$v];
      echo '<td><h4><span id="classNumber'.$id.'">'.$numA.'</span></h4></td>';
      $id++;
    }
    echo '</tr></tbody></table></div></div>';

    // Level BreakDown
    $levId = array(10,15,20,25,30,35,40,45,50,55,60,65,70,75);

    echo '<div class="level-stats">';
    echo '<h2>'.JText::_( 'COM_PBROSTER_STAT_ROSTER_LEVEL_BREAKDOWN' ).'</h2><div class="level-container"><table><tbody><tr class="graph-layout"><td onmouseover="javascript: showTheLevel(10,'.$statistikLevel['level'][10].','.$totalMembers.');"><div class="level-graph">';
    echo '<div style="height: '.$statistikLevel['level'][10].'px;" class="levelbar" id="levelBar10"></div></div></td>';
    echo '<td onmouseover="javascript: showTheLevel(11,'.$statistikLevel['level'][11].','.$totalMembers.');"><div class="level-graph"><div style="height: '.$statistikLevel['level'][11].'px;" class="levelbar" id="levelBar11"></div></div></td>';

    $i = 12;
    while ($i <= 85) {
      $numA = $statistikLevel['level'][$i];
      $numB = JText::_($statistikLevel['level'][$i]);
	  $count = $statistikLevel['level'][$i];
      if ($numA > 50) // Dont want any insane numbers, so we cut here.
        $numA = 50;
      echo '<td onmouseover="javascript: showTheLevel('.$i.','.$count.','.$totalMembers.');"><div class="level-graph"><div style="height: '.$numA.'px;" class="levelbar" id="levelBar'.$i.'"></div></div></td>';
      $i++;
    }
    echo '</tr></tbody><tbody>';
    echo '<tr class="level-range">';

    foreach ($levId as $v) {
      echo '<td colspan="5"><div class="levelicon">'.$v.'</div></td>';
    }

    echo '<td colspan="6"><div class="levelicon">80 <em style="right:-24px">85</em></div></td></tr></tbody></table>';
    echo '<div class="stats-console"><span class="tooltipGuildSmall">'.JText::_( 'COM_PBROSTER_STAT_ROSTER_LEVEL_TIP' ).'</span>';
    echo '<div class="stat-padding">';
    echo '<p><span class="tooltipGuild">'.JText::_( 'COM_PBROSTER_STAT_ROSTER_LEVEL_TOTAL' ).'</span><strong>&nbsp;'.$totalMembers.'</strong></p>';
	echo '<p><span class="tooltipGuild">&nbsp;</span></p>';
	echo '<p><span id="countSpecificLevel" class="tooltipGuild"># '.JText::_( 'COM_PBROSTER_STAT_ROSTER_LEVEL_OF_LEVEL' ).' <b id="replaceLevelNum">85</b>s:</span>&nbsp;<strong id="printNum">'.$statistikLevel['level'][80].'</strong></p>';
	
	$count2 = (($statistikLevel['level'][85]/$totalMembers)*100);
    $pct = number_format($count2, 0);
	
	echo '<p><span class="tooltipGuild">% '.JText::_( 'COM_PBROSTER_STAT_ROSTER_LEVEL_OF_LEVEL' ).' <b id="replaceLevelPercent">85</b><b id="countSpecificLevel"></b>s:</span>&nbsp;<b id="printPercent">'.$pct.'</b>%</p>';
    echo '</div>';
?>
<script language="javascript">
function showTheLevel(num,count,total){
document.getElementById('replaceLevelNum').innerHTML =num;
document.getElementById('printNum').innerHTML =count;
document.getElementById('replaceLevelPercent').innerHTML =num;
$percent = Math.round(count/total*100)
document.getElementById('printPercent').innerHTML =$percent;
}
</script>
<?php
    HTML_Roster::footerButtons();
	echo '<div class="footer-fader"></div>';
	HTML_Roster::rosterFooter($config);
	echo '</div></div></div>';
  }
  
}


?>
